package com.ymkj.testdemo.stackoverflow;

import java.util.ArrayList;
    import java.util.Scanner;

    public class Main {

        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            ArrayList<Item> items = new ArrayList<>();

            while (true) {

                System.out.println("Identifier? (empty will stop)");
                String identifier = scanner.nextLine();

                if (identifier.isEmpty()) {
                    break;
                }

                System.out.println("Name? (empty will stop)");
                String name = scanner.nextLine();

                if (name.isEmpty()) {
                break;
                }
                /*if (!items.contains(identifier)){   This doesn't work
                    items.add(new Item(identifier, name));
                }*/
                
                if (!items.contains(new Item(identifier,name))) {
                items.add(new Item(identifier, name));  //this works fine, but I want to skip even if only the ID is equal
                }
            }

            System.out.println("");
            System.out.println("==Items==");
            for (Item lines : items) {
               System.out.println(lines);
            }
        }
    }
